/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package UserLogin.Logic;

import Data.DAO.iUserStore;
import Data.DAO.IDataStore;
import data.pojo.User;
import java.util.ArrayList;

/**
 *
 * @author Administrator
 */
public class UserLogin {
   private ArrayList<User> List = new ArrayList<User>();
   private IDataStore userDS = new iUserStore();
  public UserLogin(){
     // userDS.update(List);
       List= (ArrayList<User>) userDS.getObjects();
       System.out.println(List.size());
     // List.add(u1);
  }
  private User u1 = new User();
  private String status ;
  //private String status ;
  
  
  
  public String hasIdentity(User user){
      if(this.isValid(user)){
          return u1.getStatus();
      }
      else
          return null ;
  }
  
 
  private boolean isValid(User user){
      System.out.println("用户的id是"+user.getId());
      if((user.getId().equals("0"))&&(user.getPassword().equals("0"))){
               user.setStatus("系统管理员");
               u1=user;
               return true ;
  }
       for(User u : List){
           if(u.getId().equals(user.getId())){
           if(u.getPassword().equals(user.getPassword())){
               u1=u;
               return true ;
           }
             
        }
       }
      
      
        return false;
    }
   
       
       
   
}
